package cn.com.chengq.javafx.mvc;

import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.Label;

import java.io.IOException;
import java.net.URL;
import java.util.Random;
import java.util.ResourceBundle;

public class AppUI implements Initializable {
    public Label text;
    private AppModel model = new AppModel();


    @Override
    public void initialize(URL location, ResourceBundle resources) {
        text.textProperty().bindBidirectional(model.textProperty());
        // model.setText("");
    }

    public static Parent load() throws IOException {
        return FXMLLoader.load(AppUI.class.getResource("AppUI.fxml"));
    }

    public void click(ActionEvent event) {
        String[] strs = new String[] {"A", "B", "C", "D"};
        model.setText(strs[new Random().nextInt(strs.length)]);
    }
}
